// pages/user/students/students.ts

import msg from "../../../utils/msg";
import { AnalysisS, AnalysisSExport } from "../../../utils/request/api";
import User from "../../../utils/user"

Page({

  /**
   * 页面的初始数据
   */
  data: {
    all:[] as any,
    overview:[] as any,
    week:0 as number,
    user:{} as User,
    s_name:'',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options:any) {
    let user = new User;
    let s_code=options.s_code;
    let s_name=options.s_name;
    if(!s_code) {
      s_code=user.code;
      s_name=user.name;
    }
    this.setData({
        s_code:s_code,
        s_name:s_name,
        user:user,
    })
    AnalysisS({s_code:s_code})
    .then((res:any)=>{
        this.init(res);
    });
  },
  onClickLeft() {
    wx.navigateBack();
  },
  init(res:any){
    let overview = res.data.data.overview;
    let all = res.data.data.all;
    let week = res.data.data.week;
    this.setData({
        overview:overview,
        all:all,
        week:week,
    })
  },
  export:async function(){
    msg.Loading('导出中');
    await AnalysisSExport({data:{s_code:this.data.user.code},fileName:this.data.user.name+'签到情况报表'});
    msg.hideLoading();
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})